<!-- 内容模块 -->
<template>
    <router-view v-slot="{ Component }" v-if="flag" >
        <keep-alive >
            <component :key="$route.name" :is="Component"  />
        </keep-alive>
    </router-view>

</template>
<script setup lang='ts'>
import { onMounted, ref, watch, nextTick} from 'vue'
import useLayOutSettingStore from '@/store/modules/setting';
import { slotFlagsText } from '@vue/shared';
import { EBizCode, ELocalStorageKey, ERouterName } from '@/types'
import { useRouter } from 'vue-router'

import { useConnectWebSocket } from '@/hooks/use-connect-websocket'
import rootStore from '@/store/other/aboutDev'
import EventBus from '@/event-bus'

const store = rootStore
let $router = useRouter();
let LayOutSettingStore = useLayOutSettingStore()
let flag = ref(true)
watch(()=>LayOutSettingStore.refsh,()=>{
    flag.value = false;
    nextTick(()=>{
        flag.value = true;
    })
})
const messageHandler = async (payload: any) => {
  if (!payload) {
    return
  }

  switch (payload.biz_code) {
    case EBizCode.GatewayOsd: {
      store.commit('SET_GATEWAY_INFO', payload.data)
      break
    }
    case EBizCode.DeviceOsd: {
      store.commit('SET_DEVICE_INFO', payload.data)
      break
    }
    case EBizCode.DockOsd: {
      store.commit('SET_DOCK_INFO', payload.data)
      break
    }
    case EBizCode.MapElementCreate: {
      store.commit('SET_MAP_ELEMENT_CREATE', payload.data)
      break
    }
    case EBizCode.MapElementUpdate: {
      store.commit('SET_MAP_ELEMENT_UPDATE', payload.data)
      break
    }
    case EBizCode.MapElementDelete: {
      store.commit('SET_MAP_ELEMENT_DELETE', payload.data)
      break
    }
    case EBizCode.DeviceOnline: {
      store.commit('SET_DEVICE_ONLINE', payload.data)
      break
    }
    case EBizCode.DeviceOffline: {
      store.commit('SET_DEVICE_OFFLINE', payload.data)
      break
    }
    case EBizCode.FlightTaskProgress:
    case EBizCode.FlightTaskMediaProgress:
    case EBizCode.FlightTaskMediaHighestPriority: {
      EventBus.emit('flightTaskWs', payload)
      break
    }
    case EBizCode.DeviceHms: {
      store.commit('SET_DEVICE_HMS_INFO', payload.data)
      break
    }
    case EBizCode.DeviceReboot:
    case EBizCode.DroneOpen:
    case EBizCode.DroneClose:
    case EBizCode.CoverOpen:
    case EBizCode.CoverClose:
    case EBizCode.PutterOpen:
    case EBizCode.PutterClose:
    case EBizCode.ChargeOpen:
    case EBizCode.ChargeClose:
    case EBizCode.DeviceFormat:
    case EBizCode.DroneFormat:
    {
      store.commit('SET_DEVICES_CMD_EXECUTE_INFO', {
        biz_code: payload.biz_code,
        timestamp: payload.timestamp,
        ...payload.data,
      })
      break
    }
    case EBizCode.ControlSourceChange:
    case EBizCode.FlyToPointProgress:
    case EBizCode.TakeoffToPointProgress:
    case EBizCode.JoystickInvalidNotify:
    case EBizCode.DrcStatusNotify:
    {
      EventBus.emit('droneControlWs', payload)
      break
    }
    default:
      break
  }
}


useConnectWebSocket(messageHandler)

onMounted(() => {
  const token = localStorage.getItem(ELocalStorageKey.Token)
  if (!token) {
   $router.push(ERouterName.PROJECT)
  }
})

</script>
<script lang="ts">
export default{
    name:"webhome"
}
</script>
<style scoped lang='scss'> 

 
</style >
